﻿using System;
using System.Collections.Generic;

namespace YArchitech.Plumbing
{
	internal class PumpSelConditionInfo : PumpSelectionBase
	{
		public PumpSelConditionInfo()
		{
			this.InitInfo();
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckFactory), true));
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckType), true));
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckStructType), this.m_bStructType));
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckFitType), this.m_bFitType));
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckImpellerPos), this.m_bImpellerPos));
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckUse), this.m_bUse));
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckResistCorrede), this.m_bIsResistCorrede));
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckPerfectSeal), this.m_bIsPerfectSeal));
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckSelfDraw), this.m_bIsSelfDraw));
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckDrawAbility), this.m_bIsDrawAbility));
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckMaxPress), true));
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckMaxTemp), this.m_bTemp));
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckMinTemp), this.m_bTemp));
			this.lstSelPumpCheckfun.Add(new PumpSelConditionInfo.SelPumpCheckFun(new PumpSelConditionInfo.CheckFun(this.CheckFlowType), true));
		}

		private void InitInfo()
		{
			this.m_bIsSpeedCanChange = false;
			this.m_dMinSpeedRate = 1.0;
			this.m_bIsImpellerCanCut = false;
			this.m_dMinCutRate = 1.0;
			this.m_bIsResistCorrede = false;
			this.m_bIsPerfectSeal = false;
			this.m_bIsSelfDraw = false;
			this.m_dQNeeded = 100.0;
			this.m_dHNeeded = 80.0;
			this.m_dEfficiencyNeeded = 70.0;
			this.m_bRangeMatch = true;
			this.m_dQNeeded_Max = 110.0;
			this.m_dHNeeded_Max = 90.0;
			this.m_dEfficiency_Max = 85.0;
			this.m_dQTolerance = 0.1;
			this.m_dHTolerance = 0.1;
			this.m_dETolerance = 0.1;
			this.m_strFlowtype = "清水";
			this.m_dTemperature = 20.0;
			this.m_dMaxTemp = 80.0;
			this.m_dMinTemp = 0.0;
			this.m_dMaxPressure = 2.0;
			this.m_bPipeOpen = true;
			this.m_dAirPressure = 0.101325;
			this.m_dDrawPipeLose = 0.0;
			this.m_dFitHeight = 0.0;
			this.m_dConstPressue = 0.6;
			this.m_dDrawSafeCofficient = 1.1;
			this.m_bIsDrawAbility = true;
		}

		private bool CheckFactory(HYPumpData pump)
		{
			return this.m_strFactory.Contains("全部") || this.m_strFactory.CompareTo(pump.StrFactory) == 0;
		}

		private bool CheckType(HYPumpData pump)
		{
			return this.m_strType.Contains("全部") || this.m_strType.CompareTo(pump.StrBaseType) == 0;
		}

		private bool CheckStructType(HYPumpData pump)
		{
			return this.m_strStructType.Contains("全部") || this.m_strStructType.CompareTo(pump.StrStructType) == 0;
		}

		private bool CheckFitType(HYPumpData pump)
		{
			return this.m_strFitType.Contains("全部") || this.m_strFitType.CompareTo(pump.StrFitType) == 0;
		}

		private bool CheckImpellerPos(HYPumpData pump)
		{
			return this.m_strImpellerPos.Contains("全部") || this.m_strImpellerPos.CompareTo(pump.StrImpellerPos) == 0;
		}

		private bool CheckUse(HYPumpData pump)
		{
			return this.m_strUse.Contains("全部") || this.m_strUse.CompareTo(pump.StrUse) == 0;
		}

		private bool CheckResistCorrede(HYPumpData pump)
		{
			return this.m_bIsResistCorrede == pump.BResistcorrosion;
		}

		private bool CheckPerfectSeal(HYPumpData pump)
		{
			return this.m_bIsPerfectSeal == pump.bPefectSeal;
		}

		private bool CheckSelfDraw(HYPumpData pump)
		{
			return this.m_bIsSelfDraw == pump.BDrawbyself;
		}

		public bool CheckDrawAbility(HYPumpData pump)
		{
			if (!this.m_bIsDrawAbility)
			{
				return true;
			}
			double dDrawPipeLose = this.m_dDrawPipeLose;
			double dFitHeight = this.m_dFitHeight;
			double num = this.m_bRangeMatch ? pump.GetMaxQ() : pump.DQ;
			double num2 = pump.DIn;
			if (num2 <= 0.0)
			{
				return false;
			}
			num2 /= 1000.0;
			num /= 3600.0;
			double num3 = num / (Math.PI * num2 * num2 / 4.0);
			double densityByTemperature = WaterAndAirCal.GetDensityByTemperature(this.m_dTemperature);
			double num4 = WaterAndAirCal.GetPs(this.m_dTemperature) / (WaterAndAirCal.C_dg * densityByTemperature);
			double num5 = WaterAndAirCal.C_dPs_20 / (WaterAndAirCal.C_dg * densityByTemperature);
			double num6;
			if (this.m_bPipeOpen)
			{
				num6 = this.m_dAirPressure;
			}
			else
			{
				num6 = this.m_dConstPressue;
			}
			double num7 = num6 * 1000000.0 / (WaterAndAirCal.C_dg * densityByTemperature);
			pump.GetVaccumbyQ(num);
			if (pump.eVacuumType == EVacuumType.EPVacuum_MaxHeight)
			{
				double num8 = WaterAndAirCal.C_dPa_std / (WaterAndAirCal.C_dg * densityByTemperature);
				return pump.dVacuum - (num7 - num8) - (num4 - num5) - num3 * num3 / (2.0 * WaterAndAirCal.C_dg) - dDrawPipeLose > this.m_dFitHeight * this.m_dDrawSafeCofficient;
			}
			return num7 - num4 - dDrawPipeLose - this.m_dFitHeight > pump.dVacuum * this.m_dDrawSafeCofficient;
		}

		private bool CheckMaxPress(HYPumpData pump)
		{
			return this.m_dMaxPressure < pump.DMaxPressure;
		}

		private bool CheckFlowType(HYPumpData pump)
		{
			return this.m_strFlowtype.CompareTo(pump.strFlowtype) == 0;
		}

		private bool CheckMinTemp(HYPumpData pump)
		{
			return this.m_dMinTemp >= pump.DMinTemperature;
		}

		private bool CheckMaxTemp(HYPumpData pump)
		{
			return this.m_dMaxTemp <= pump.DMaxTemperature;
		}

		public bool CheckPumpFun(HYPumpData pump)
		{
			foreach (PumpSelConditionInfo.SelPumpCheckFun selPumpCheckFun in this.lstSelPumpCheckfun)
			{
				if (selPumpCheckFun.m_bIsValid && !selPumpCheckFun.m_funChek(pump))
				{
					return false;
				}
			}
			return true;
		}

		public bool CheckFirst(List<HYPumpData> lstPumpSet, ref List<HYPumpData> lstSelPumpSet)
		{
			lstSelPumpSet.Clear();
			foreach (HYPumpData hypumpData in lstPumpSet)
			{
				if (this.CheckPumpFun(hypumpData))
				{
					lstSelPumpSet.Add(hypumpData);
				}
			}
			return true;
		}

		public void SetSelItemBools(List<bool> lstBools)
		{
			if (lstBools.Count != 9)
			{
				return;
			}
			this.m_bFactory = lstBools[0];
			this.m_bType = lstBools[1];
			this.m_bStructType = lstBools[2];
			this.m_bFitType = lstBools[3];
			this.m_bImpellerPos = lstBools[4];
			this.m_bUse = lstBools[5];
			this.m_bIsResistCorrede = lstBools[6];
			this.m_bIsPerfectSeal = lstBools[7];
			this.m_bIsSelfDraw = lstBools[8];
		}

		public void SetLimitItemSel(List<bool> lstBools)
		{
			if (lstBools.Count != this.lstSelPumpCheckfun.Count)
			{
				return;
			}
			for (int i = 0; i < lstBools.Count; i++)
			{
				PumpSelConditionInfo.SelPumpCheckFun value = this.lstSelPumpCheckfun[i];
				value.m_bIsValid = lstBools[i];
				this.lstSelPumpCheckfun[i] = value;
			}
		}

		public void SetLimitSelText(List<string> lstStr)
		{
			if (lstStr.Count < 6)
			{
				return;
			}
			this.m_strFactory = lstStr[0];
			this.m_strType = lstStr[1];
			this.m_strStructType = lstStr[2];
			this.m_strFitType = lstStr[3];
			this.m_strImpellerPos = lstStr[4];
			this.m_strUse = lstStr[5];
		}

		public void GetQRange(out double dMinQ, out double dMaxQ)
		{
			if (this.m_bRangeMatch)
			{
				dMinQ = this.m_dQNeeded;
				dMaxQ = this.m_dQNeeded_Max;
				return;
			}
			dMinQ = this.m_dQNeeded * (1.0 - this.m_dQTolerance);
			dMaxQ = this.m_dQNeeded * (1.0 + this.m_dQTolerance);
		}

		public void GetHRange(out double dMinH, out double dMaxH)
		{
			if (this.m_bRangeMatch)
			{
				dMinH = this.m_dHNeeded;
				dMaxH = this.m_dHNeeded_Max;
				return;
			}
			dMinH = this.m_dHNeeded * (1.0 - this.m_dHTolerance);
			dMaxH = this.m_dHNeeded * (1.0 + this.m_dHTolerance);
		}

		public void GetERange(out double dMinE, out double dMaxE)
		{
			if (this.m_bRangeMatch)
			{
				dMinE = this.m_dEfficiencyNeeded;
				dMaxE = this.m_dEfficiency_Max;
				return;
			}
			dMinE = this.m_dEfficiencyNeeded * (1.0 - this.m_dETolerance);
			dMaxE = ((this.m_dEfficiencyNeeded * (1.0 + this.m_dETolerance) < 100.0) ? (this.m_dEfficiencyNeeded * (1.0 + this.m_dETolerance)) : 100.0);
		}

		public string m_strFactory;

		public string m_strType;

		public string m_strStructType;

		public string m_strFitType;

		public string m_strImpellerPos;

		public string m_strUse;

		public bool m_bFactory;

		public bool m_bType;

		public bool m_bStructType;

		public bool m_bFitType;

		public bool m_bImpellerPos;

		public bool m_bUse;

		public bool m_bTemp;

		public bool m_bIsSpeedCanChange;

		public double m_dMinSpeedRate;

		public bool m_bIsImpellerCanCut;

		public double m_dMinCutRate;

		public bool m_bIsResistCorrede;

		public bool m_bIsPerfectSeal;

		public bool m_bIsSelfDraw;

		public double m_dQNeeded;

		public double m_dHNeeded;

		public double m_dEfficiencyNeeded;

		public bool m_bRangeMatch;

		public double m_dQNeeded_Max;

		public double m_dHNeeded_Max;

		public double m_dEfficiency_Max;

		public double m_dQTolerance;

		public double m_dHTolerance;

		public double m_dETolerance;

		public double m_dMaxPressure;

		public string m_strFlowtype;

		public double m_dTemperature;

		public bool m_bPipeOpen;

		public bool m_bIsDrawAbility;

		public double m_dMaxTemp;

		public double m_dMinTemp;

		public double m_dAirPressure;

		public double m_dDrawPipeLose;

		public double m_dFitHeight;

		public double m_dConstPressue;

		public double m_dDrawSafeCofficient;

		private List<PumpSelConditionInfo.SelPumpCheckFun> lstSelPumpCheckfun = new List<PumpSelConditionInfo.SelPumpCheckFun>();

		private struct SelPumpCheckFun
		{
			public SelPumpCheckFun(PumpSelConditionInfo.CheckFun fun, bool bIsValid = true)
			{
				this.m_funChek = fun;
				this.m_bIsValid = bIsValid;
			}

			public PumpSelConditionInfo.CheckFun m_funChek;

			public bool m_bIsValid;
		}

		private delegate bool CheckFun(HYPumpData pump);
	}
}
